/*
 * @(#)BabyInfoPrefs.java	 Jan 13, 2012
 *
 * Copyright 2004-2012 WXXR Network Technology Co. Ltd. 
 * All rights reserved.
 * 
 * WXXR PROPRIETARY/CONFIDENTIAL.
 */

package com.ykdl.member.kid.prefs;

import com.ykdl.member.base.GlobalContext;

import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
/**
 * 
 * 存放 从服务器 取回来的 baby infor的信息
 *
 * <p>detailed comment
 * @author yangrunfei 2013-3-4
 * @see
 * @since 1.0
 */
public class BabyInfoPrefs {
	private static final String PREFERENCE_NAME = "babyInfo";
	private static SharedPreferences.Editor editor;
	private static SharedPreferences sharedPreferences;
	private final static String BABYINFO = "babyInfo";

	public BabyInfoPrefs(Context context) {
		if (editor == null) {
			if (sharedPreferences == null) {
				sharedPreferences = context.getSharedPreferences(PREFERENCE_NAME,
						Activity.MODE_PRIVATE);
				editor = sharedPreferences.edit();
			} else {
				editor = sharedPreferences.edit();
			}
		}
	}

	public static boolean isInit() {
		boolean isInit = true;
		if (editor == null) {
			isInit = false;
		} else {
			isInit = true;
		}
		return isInit;
	}

	public static void update(String babyInfo) {
		if(sharedPreferences==null&&GlobalContext.mContext!=null){
			sharedPreferences = GlobalContext.mContext.getSharedPreferences(PREFERENCE_NAME,
					Activity.MODE_PRIVATE);
			editor = sharedPreferences.edit();			
		}
		editor.putString(BABYINFO, babyInfo);
		editor.commit();
	}

	public static String getBabyInfo() {
		if(sharedPreferences==null&&GlobalContext.mContext!=null){
			sharedPreferences = GlobalContext.mContext.getSharedPreferences(PREFERENCE_NAME,
					Activity.MODE_PRIVATE);
			editor = sharedPreferences.edit();
			
		}
		
		return sharedPreferences.getString(BABYINFO, null);
	}
	
	


}
